﻿using System.Collections;
using System.Collections.Generic;
using System.IO;

namespace FileParser
{
    public abstract class FileParserBase<TRecordType> : IFileParser<TRecordType>
    {
        private readonly string _fileName;
        private readonly char _splitter;

        protected FileParserBase(string fileName, char splitter)
        {
            _fileName = fileName;
            _splitter = splitter;
        }

        public IEnumerator<TRecordType> GetEnumerator()
        {
            return new FileEnumerator<TRecordType>(_fileName, BuildRecord, _splitter);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        protected abstract TRecordType BuildRecord(string[] fields);

        public delegate TRecordType BuildRecordDeleage(string[] fields);

    }
}